<h1><?php echo dl_lang_general("main.write_message"); ?></h1>

<?php 
setMessages();
if (!isset($data["formMessage"])) 
{
    $data["formMessage"] = array();
}

if (isset($_GET["arg2"]) && $_GET["arg2"] != "")
{
    // odpovídá na zprávu, kterou dostal?
    $s = dibi::query("SELECT COUNT(*) FROM account_messages WHERE id = %i", $_GET["arg2"], "AND mess_to = %i", $data["user"]["id"]);
    $kontrola = $s->fetchSingle();
    if ($kontrola > 0)
    {
        $s = dibi::query("SELECT m.id, a.name, m.mess_read, m.title, m.message
                            FROM account a, account_messages m
                           WHERE a.id = m.mess_from
                             AND m.mess_to = %i", $data["user"]["id"],
                            "AND m.id = %i", $_GET["arg2"]);
        $r = $s->fetchAll();
        $data["formMessage"] = array("account" => $r[0]->name,
                                     "title"   => "RE: ".$r[0]->title,
                                     "text"    => "\n\n\n---------------------------------------------------------\n".$r[0]->message);
    }
}
?>

<form method="post" action="" name="sendMessageForm">
    <input type="hidden" name="xfunction" value="xsendMessage">
    <table align="center" cellpadding="2">
        <tr>
            <th><?php echo dl_lang_general("form.messages_to"); ?></th>
            <td><?php echo form_text("account", $data["formMessage"], 30, 30, "account"); ?></td>
        </tr>
        <tr>
            <th><?php echo dl_lang_general("form.messages_title"); ?></th>
            <td><?php echo form_text("title", $data["formMessage"], 30, 50); ?></td>
        </tr>
        <tr>
            <th valign="top"><?php echo dl_lang_general("form.messages_body"); ?></th>
            <td><?php echo form_textarea("text", $data["formMessage"], 10, 50); ?></td>
        </tr>
    </table>
    <center><button onclick='sendMessageForm.submit();'><?php echo dl_lang_general("form.messages_send"); ?></button></center>
</form>

<?php
unset($data["formMessage"]);
?>